<?php

namespace app\controller;


use app\BaseController;
use app\dto\PageDto;
use app\dto\UserDto;
use app\model\AppFun;
use app\model\Menu;
use app\model\ModifyQuery;
use app\model\SysClass;
use app\model\SysDictionary;
use app\model\User;
use app\model\BaseQuery;
use app\model\WenZhang;
use app\Request;
use app\service\RedisService;
use app\utils\Md5;
use app\utils\Utils;
use app\validate\WenzhangValidate;
use Cassandra\Date;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;
use think\File;


class FileController extends BaseController
{


    /**
     * @desc 上传一个文件
     *
     */
    function uploadOne(Request $request)
    {
        $files = $request->file();
        $file = $files['file'];
//        var_dump($files);
        /*上传文件到指定文件
          新增文件夹
          构建文件名
          移动
        */
        $dicName = Utils::fdate(time(), '/y/m/d');
        $dicpath = Config("filesystem.disks.public.root") .$dicName;
        if (!file_exists($dicpath)) {
            mkdir($dicpath, 0700, true);
        }
        $ext = $file->getOriginalExtension();

        $fileInfo = pathinfo($file);
        // 获取文件地址和名称
        $filePath = $fileInfo['dirname'] . '/' . $fileInfo['basename'];
        // 文件地址转文件类
        $fileUp = new File($filePath);
        $filesavename = $fileUp->md5() . '.' . $ext;
        $finalpath = $dicpath . '/' . $filesavename;
        $webUrl = Config("filesystem.disks.public.url") .'/'.$dicName . '/' . $filesavename;
        $fileUp->move($dicpath, $finalpath);
        return Utils::ok($webUrl);
    }

    function zipFileList($fileList){
        /*
         * 1  新建一个文件夹
         * 2  这个文件夹下新增文件多个
         * 3  压缩这个文件夹
         * */
    }
}